<!DOCTYPE html>
<!--suppress ALL -->
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      layout:decorator="layout">
<body>
<section layout:fragment="content">
    <div class="main">
        <div class="logo">
            <img src="img/logo1.png" th:src="@{/static/img/logo1.png}"/>
        </div>
        <ul class="ui-row op">
            <li class="ui-col ui-col-50 ">
                <label><input type="radio"  name="userType" checked="checked" value="0" class="userType" />校友</label>
            </li>
            <li class="ui-col ui-col-50">
                <label><input type="radio"  name="userType" value="1" class="userType" />北大之友</label>
            </li>
        </ul>
    </div>
    <div class="bgf redcard-money size30">
        <div class="money-tips width90 margin0auto">
            <div style="border-bottom: 1px solid #d1d1d1;margin-bottom: 1rem;">
                我要认领
            </div>
            <ul class="ui-tiled" style="width: 100%;">
                <li><div class="uNum active noLimite">不限制</div></li>
                <li><div class="uNum">10个</div></li>
                <li><div class="uNum">20个</div></li>
                <li><div class="uNum">100个</div></li>
            </ul>
            <p class="tag clear">*每个红包1.18元</p>
            <div class="write-money">
                <div class="even">
                    自定义
                    <div class="write-inp"><input type="tel" class="definedNum" placeholder="请输入" /> 个</div>
                </div>
            </div>
        </div>
    </div>
    <div class="bgf">
        <div class="width90 margin0auto even">
            <span class="bth9b">*</span>召集令名称
            <div class="write-inp" style="width: 60%;">
                <input type="text" class="zjlName"  placeholder="请输入10字以内" />
            </div>
        </div>
    </div>

    <div id="fqzjl" class="rbtn give-redcard">发起召集令</div>
    <script src="/static/js/json2.js" th:src="@{/static/js/json2.json}"/>
    <script>
        $(function(){
            var $fqzjl = $("#fqzjl"),  //发起按钮
                    $definedNum = $(".definedNum"), //自定义个数
                    $uNum = $(".uNum"), //所选择的几个红包
                    $zjlName = $(".zjlName"), //召集令名称
                    uMoney = 0.01;
            $uNum.on("click",function(){
                $uNum.removeClass("active");
                $(this).addClass("active");
                var _v = parseInt($(this).text()).toFixed(0);
                $definedNum.val("")
            });
            $definedNum.on("keyup",function(){
                var _v = parseInt($(this).val());
                if(_v>0){
                    $uNum.removeClass("active");
                    $(this).val(_v);
                }
            }).on("blur",function(){
                if( 0 >= $(this).val() ){
                    $(this).val(1);
                }
            });
            $fqzjl.on("click",function(){
                var _uType = $(".userType:checked").val();
                var $active = $(".uNum.active");
                var _uNum=0;
                if($definedNum.val()){
                    _uNum = $definedNum.val();
                }else if(!$active.hasClass("noLimite")){
                    _uNum = parseInt($active.text())
                }else if($active.hasClass("noLimite")){
                    _uNum = -1;
                }
                var _zjlName = $zjlName.val();
                var data = {'uType':_uType,'name' :_zjlName,'totalShare':_uNum};
                if(_zjlName != ""){
                    $.ajax({
                        type:"POST",
                        contentType: 'application/json',
                        url: "/peking/gift-call/save",
                        data:JSON.stringify(data),
                        success:function(res){
                            if(res == "GC_SAVE_ERROR"){
                                alert("召集令已存在!");
                            }else{
                                window.location.href = "/peking/gift-call/"+res.result.id+"/success";
                            }
                        },
                        error:function(){
                            alert("召集令已存在!");
                        }
                    })
                }else{
                    alert("请输入姓名");
                    return false;
                }


            })
        })
    </script>

</section>

</body>
</html>